﻿#include "stdafx.h"
#include "ErosionTask.h"
#include <QVBoxLayout>
#include <QSpinBox>
#include <QPushButton>
#include <QLabel>
void ErosionTask::execute(cv::Mat& image)
{
	cv::Mat kernel = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(kernelSize, kernelSize));
	cv::erode(image, image, kernel, cv::Point(-1, -1), iterations);
}



std::string ErosionTask::getName() const
{
	return "腐蚀";
}


std::unique_ptr<QDialog> ErosionTask:: getConfigUI()  {
	// 创建一个配置对话框（基于Qt）
	auto dialog = std::make_unique<QDialog>();
	QVBoxLayout* layout = new QVBoxLayout(dialog.get());

	// 添加核大小输入
	QSpinBox* kernelSpin = new QSpinBox();
	kernelSpin->setRange(1, 15);
	kernelSpin->setValue(kernelSize);
	layout->addWidget(new QLabel("核大小:"));
	layout->addWidget(kernelSpin);

	// 添加迭代次数输入
	QSpinBox* iterSpin = new QSpinBox();
	iterSpin->setRange(1, 10);
	iterSpin->setValue(iterations);
	layout->addWidget(new QLabel("迭代次数:"));
	layout->addWidget(iterSpin);

	// 添加确认按钮
	QPushButton* okButton = new QPushButton("确认");
	layout->addWidget(okButton);

	// 连接信号：用户确认后保存参数
	QObject::connect(okButton, &QPushButton::clicked, dialog.get(), [&, kernelSpin, iterSpin]() {
		kernelSize = kernelSpin->value();
		iterations = iterSpin->value();
		dialog->accept();
		});

	return dialog;
}


